package flc.ast.adapter;

import androidx.annotation.NonNull;

import com.blankj.utilcode.util.AppUtils;
import com.blankj.utilcode.util.FileUtils;
import com.chad.library.adapter.base.provider.BaseItemProvider;
import com.chad.library.adapter.base.viewholder.BaseViewHolder;

import flc.ast.R;
import flc.ast.bean.ApkBean;
import flc.ast.utils.MyUtils;
import stark.common.basic.adaptermutil.StkProviderMultiAdapter;
import stark.common.basic.adaptermutil.StkSingleSpanProvider;

public class ApkCollAdapter extends StkProviderMultiAdapter<ApkBean> {

    public ApkCollAdapter() {
        addItemProvider(new StkSingleSpanProvider<>(98));
        addItemProvider(new ApkCollProvider());
    }

    private class ApkCollProvider extends BaseItemProvider<ApkBean> {
        @Override
        public int getItemViewType() {
            return StkProviderMultiAdapter.TYPE_VIEW;
        }

        @Override
        public int getLayoutId() {
            return R.layout.item_apk_coll;
        }

        @Override
        public void convert(@NonNull BaseViewHolder baseViewHolder, ApkBean bean) {
            baseViewHolder.setImageDrawable(R.id.ivApkCollItemLog, AppUtils.getAppIcon(bean.pkgName));
            baseViewHolder.setText(R.id.tvApkCollItemName, AppUtils.getAppName(bean.pkgName));
            baseViewHolder.setText(R.id.tvApkCollItemPackName, getContext().getString(R.string.packagename_text) + bean.pkgName);
            baseViewHolder.setText(R.id.tvApkCollItemSize, getContext().getString(R.string.size_text) + FileUtils.getSize(AppUtils.getAppPath(bean.pkgName)));
        }
    }
}
